<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>设置-个人信息</title>
    <link rel="icon" href="/assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
    <link rel="stylesheet" href="css/cropper.min.css">
    <link rel="stylesheet" href="css/ImgCropping.css">
</head>

<body>
<!--页面顶部白条条，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
<div class="nav-bottom"></div>
<script type="text/javascript">$(".nav-bottom").load("top.html");</script>

<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
<script type="text/javascript" src="js/plugins/birthday/birthday.js"></script>
<script type="text/javascript" src="js/plugins/citypicker/distpicker.data.js"></script>
<script type="text/javascript" src="js/plugins/citypicker/distpicker.js"></script>
<script type="text/javascript" src="js/plugins/upload/uploadPreview.js"></script>
<script type="text/javascript" src="js/pages/main.js"></script>
<script>
    $(function () {
        $.ms_DatePicker({
            YearSelector: "#select_year2",
            MonthSelector: "#select_month2",
            DaySelector: "#select_day2"
        });
    });
</script>
</body>
<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                    <div class="person-account">
                        <span class="name">{{user.username}}</span>
                        <span class="safe"><a href="#">退出登录</a></span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="home-index.html">我的订单</a></dd>
                        <dd><a href="home-order-pay.html">待付款</a></dd>
                        <dd><a href="home-order-send.html">待发货</a></dd>
                        <dd><a href="home-order-receive.html">待收货</a></dd>
                        <dd><a href="home-order-evaluate.html">待评价</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 我的中心</dt>
                        <dd><a href="home-person-collect.html">我的收藏</a></dd>
                        <dd><a href="home-person-footmark.html">我的足迹</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 物流消息</dt>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="home-setting-info.html" class="list-active">个人信息</a></dd>
                        <dd><a href="home-setting-address.html">地址管理</a></dd>
                        <dd><a href="home-setting-safe.html">安全管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6">
                <div class="body userInfo">
                    <ul class="sui-nav nav-tabs nav-large nav-primary ">
                        <li class="active"><a href="#one" data-toggle="tab">基本资料</a></li>
                        <li><a href="#two" data-toggle="tab">头像照片</a></li>
                    </ul>
                    <div class="tab-content ">
                        <div id="one" class="tab-pane active">
                            <form id="form-msg" class="sui-form form-horizontal" ref="infoForm"
                                  @submit.prevent="submit">
                                <div class="control-group">
                                    <label for="inputName" class="control-label">昵称：</label>
                                    <div class="controls">
                                        <input type="text" id="inputName" v-model="inputtext.niackname" name="email"
                                               placeholder="昵称">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputGender" class="control-label">性别：</label>
                                    <div class="controls">
                                        <label data-toggle="radio" class="radio-pretty inline">
                                            <input type="radio" name="gender" v-model="inputtext.gender"
                                                   value="1"><span>男</span>
                                        </label>
                                        <label data-toggle="radio" class="radio-pretty inline">
                                            <input type="radio" name="gender" v-model="inputtext.gender"
                                                   value="2"><span>女</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">生日：</label>
                                    <div class="controls">
                                        <select id="select_year2" :rel="inputtext.select_year2"
                                                v-model="inputtext.select_year2"></select>年
                                        <select id="select_month2" rel="inputtext.select_month2"
                                                v-model="inputtext.select_month2"></select>月
                                        <select id="select_day2" rel="inputtext.select_day2"
                                                v-model="inputtext.select_day2"></select>日
                                    </div>
                                </div>


                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">所在地：</label>
                                    <div class="controls">
                                        <div data-toggle="distpicker">
                                            <div class="form-group area">
                                                <select class="form-control" id="province1"
                                                        v-model="inputtext.province"></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" id="city1"
                                                        v-model="inputtext.city"></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" id="district1"
                                                        v-model="inputtext.areas"></select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputJob" class="control-label">职业：</label>
                                    <div class="controls"><span class="sui-dropdown dropdown-bordered select"><span
                                            class="dropdown-inner"><a role="button" data-toggle="dropdown" href="#"
                                                                      class="dropdown-toggle">
                                                <input name="job" type="hidden" data-rules="required" ref="job"><i
                                            class="caret"></i><span>{{inputtext.job ? inputtext.job:请选择}}</span></a>
                                            <ul id="menu4" role="menu" aria-labelledby="drop4"
                                                class="sui-dropdown-menu">
                                                <li role="presentation"><a role="menuitem" tabindex="-1"
                                                                           href="javascript:void(0);"
                                                                           value="程序员">程序员</a></li>
                                                <li role="presentation"><a role="menuitem" tabindex="-1"
                                                                           href="javascript:void(0);"
                                                                           value="产品经理">产品经理</a></li>
                                                <li role="presentation"><a role="menuitem" tabindex="-1"
                                                                           href="javascript:void(0);" value="UI设计师">UI设计师</a></li>
                                            </ul>
                                            </span>
                                            </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="sanwei" class="control-label"></label>
                                    <div class="controls">
                                        <button type="submit" class="sui-btn btn-primary">保存</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="two" class="tab-pane">

                            <div class="new-photo">
                                <p>当前头像：</p>
                                <div class="upload">
                                    <img id="imgShow_WU_FILE_0" width="100" height="100" :src="inputtext.image"
                                         alt="暂无图片">
                                    <input type="file" id="up_img_WU_FILE_0" @change="image()"/>
                                </div>
                            </div>
                            <br>
                            <hr>
                            <div>
                                <p>历史头像：</p>
                                <div class="upload yui3-u-1-5" v-for="(image,index) in inputtext.images" :key="index">
                                    <img id="oldimage" width="100" height="100" :src="image.image" alt="暂无图片"><br>
                                    <button @click="updateimage(image.image)">设置</button>
                                    <button @click="deleteimage(index)">删除</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: "#account",
        data: {
            ly,
            inputtext: {
                id: "",
                image: "",
                gender: 1,
                images: [],
                job: "",
                select_year2: 2018,
                select_month2: 1,
                select_day2: 1,
                province: "",
                city: "",
                areas: ""
            },
            img: {
                iamge: "",
                infoId: ""
            },
            user:{}
        },
        created() {
            ly.verifyUser()
                .then(resp => {
                    this.user = resp.data;
                    this.findInfo();
                })
                .catch(() => {
                    // 去登录
                    this.gotoLogin();
                });
        },
        methods: {
            image(e) {
                let reader = new FileReader();
                let img1 = event.target.files[0];
                let type = img1.type;//文件的类型，判断是否是图片
                let size = img1.size;//文件的大小，判断图片的大小
                if (size > 5242880) {
                    alert('请选择3M以内的图片！');
                    return false;
                }
                var uri = ''
                let form = new FormData();
                form.append('file', img1, img1.name);
                ly.http.post('/upload/image', form, {
                    headers: {'Content-Type': 'multipart/form-data'}
                }).then(response => {
                    console.log(response);
                    // this.inputtext.images.add(this.inputtext.image);
                    this.inputtext.image = response.data;
                    ly.http.post("/user/info/add", this.inputtext).then(res => {

                        /*this.img.infoId = this.inputtext.id;
                        this.img.iamge = this.inputtext.image;*/
                        this.findInfo();
                    })
                })
            },
            submit() {
                console.log(this.$refs.job.value)
                this.inputtext.job = this.$refs.job.value;
                const birthday = this.inputtext.select_year2 + "-" + this.inputtext.select_month2 + "-" + this.inputtext.select_day2;
                this.inputtext.birthday = new Date(birthday);
                console.log(this.inputtext.job)
                ly.http.post("/user/info/add", this.inputtext).then(res => {
                    alert("保存成功");
                }).catch(() => {
                    alert("保存失败");
                })
            },
            findInfo() {
                ly.http.get("/user/info/find").then(res => {
                    const birthday = new Date(ly.formatDate(res.data.birthday, "yyyy-MM-dd"));
                    this.inputtext.birthday = birthday
                    this.inputtext.select_year2 = birthday.getFullYear();
                    this.inputtext.select_month2 = birthday.getMonth() + 1;
                    this.inputtext.select_day2 = birthday.getDate();
                    console.log(this.inputtext.select_day2)
                    // this.inputtext
                    this.inputtext.gender = res.data.gender;
                    // this.inputtext=res.data;
                    this.inputtext.id = res.data.id;
                    this.inputtext.niackname = res.data.niackname;
                    this.inputtext.image = res.data.image;
                    this.inputtext.images = res.data.images;
                    this.$refs.job.value = res.data.job;
                    this.inputtext.job = res.data.job;
                })
            },
            gotoLogin() {
                window.location = "login.html?returnUrl=" + window.location;
            },
            updateimage(image) {
                this.inputtext.image = image;
                ly.http.post("/user/info/add", this.inputtext).then(res => {

                })
            },
            deleteimage(i) {
                /*this.img.iamge=image;
                this.img.infoId=this.inputtext.id;*/
                ly.http.put("/user/info/deleteimage", this.inputtext.images[i]).then(res => {
                    this.inputtext.images.splice(i, 1);
                })
            }
        }
    });
</script>
<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->
</html>